package cn.piaoyi.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.piaoyi.bean.Address;
import cn.piaoyi.bean.Admin;
import cn.piaoyi.bean.Category;
import cn.piaoyi.bean.City;
import cn.piaoyi.bean.Goods;
import cn.piaoyi.bean.OrderInfo;
import cn.piaoyi.bean.Province;
import cn.piaoyi.bean.UserInfo;
import cn.piaoyi.comm.Constant;
import cn.piaoyi.comm.Util;
import cn.piaoyi.exception.PiaoyiException;
import cn.piaoyi.service.AddressService;
import cn.piaoyi.service.AdminService;
import cn.piaoyi.service.CategoryService;
import cn.piaoyi.service.CityService;
import cn.piaoyi.service.CommentService;
import cn.piaoyi.service.GoodsService;
import cn.piaoyi.service.OrderInfoService;
import cn.piaoyi.service.PosterService;
import cn.piaoyi.service.UserInfoService;
import cn.piaoyi.service.web.PageList;
import cn.piaoyi.service.web.Pages;
import cn.piaoyi.web.interceptor.RemoteAddrAware;
import cn.piaoyi.web.interceptor.UserSessionAware;
import cn.piaoyi.web.servlet.AdminSession;
import cn.piaoyi.web.servlet.UserSession;
import cn.piaoyi.web.ui.OptionsInt;
import cn.piaoyi.web.ui.OptionsLong;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.SessionAware;

public class UserOrderInfo extends BaseAction implements SessionAware,UserSessionAware{
	private static final Log logger = LogFactory.getLog(UserOrderInfo.class);
	
	private OrderInfoService orderInfoService;
	private UserInfoService userInfoService;

	public OrderInfoService getOrderInfoService() {
		return orderInfoService;
	}

	public void setOrderInfoService(OrderInfoService orderInfoService) {
		this.orderInfoService = orderInfoService;
	}
	
	public UserInfoService getUserInfoService() {
		return userInfoService;
	}

	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	
	private UserSession userSession;
	private Map session;

	public UserSession getUserSession() {
		return userSession;
	}

	public void setUserSession(UserSession userSession) {
		this.userSession = userSession;
	}
	
	public Map getSession() {
		return session;
	}
	
	public void setSession(Map session) {
		this.session = session;
	}
	
	private PageList pageList;
	private UserInfo userInfo;
	private OrderInfo orderInfo;
	
	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}
	
	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}
	public OrderInfo getOrderInfo() {
		return orderInfo;
	}

	public void setOrderInfo(OrderInfo orderInfo) {
		this.orderInfo = orderInfo;
	}
	
	private long id;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return INPUT;
		}
	}

	/**
	 * 初始页
	 */
	public String index(){
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/user_orderinfo.action");
		this.setPageList(this.getOrderInfoService().findOrderInfos(this.getUserSession().getUid(), -1, -1, -1, "id", 1, pages));
		
		this.setUserInfo(this.getUserInfoService().findUserInfoById(getUserSession().getUid()));
		return SUCCESS;
	}
	
	public String pay(){
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/user_orderinfo.action?action=pay");
		this.setPageList(this.getOrderInfoService().findOrderInfos(this.getUserSession().getUid(), 0, -1, -1, "id", 1, pages));
		return SUCCESS;
	}
	
	public String finish(){
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/user_orderinfo.action?action=finish");
		this.setPageList(this.getOrderInfoService().findOrderInfos(this.getUserSession().getUid(), 3, -1, -1, "id", 1, pages));
		return SUCCESS;
	}
	
	public String show(){
		this.orderInfo = this.getOrderInfoService().findOrderInfoById(this.id);
		return "show";
	}
}
